/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jpa.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Giovanni
 */
@Entity
@Table(name = "user")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT u FROM User u"),
    @NamedQuery(name = "User.findByMail", query = "SELECT u FROM User u WHERE u.mail = :mail"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT u FROM User u WHERE u.password = :password"),
    @NamedQuery(name = "User.findByName", query = "SELECT u FROM User u WHERE u.name = :name"),
    @NamedQuery(name = "User.findBySurname", query = "SELECT u FROM User u WHERE u.surname = :surname"),
    @NamedQuery(name = "User.findByPublicvisibility", query = "SELECT u FROM User u WHERE u.publicvisibility = :publicvisibility")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "MAIL")
    private String mail;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "PASSWORD")
    private String password;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "NAME")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "SURNAME")
    private String surname;
    @Basic(optional = false)
    @NotNull
    @Column(name = "PUBLICVISIBILITY")
    private boolean publicvisibility;
    @ManyToMany(mappedBy = "userCollection")
    private Collection<Event> eventCollection;
    @JoinTable(name = "user_has_weathernotification", joinColumns = {
        @JoinColumn(name = "USER_MAIL", referencedColumnName = "MAIL")}, inverseJoinColumns = {
        @JoinColumn(name = "WEATHERNOTIFICATION_ID", referencedColumnName = "ID")})
    @ManyToMany
    private Collection<Weathernotification> weathernotificationCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Ack> ackCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<Invite> inviteCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user1")
    private Collection<Invite> inviteCollection1;

    public User() {
    }

    public User(String mail) {
        this.mail = mail;
    }

    public User(String mail, String password, String name, String surname, boolean publicvisibility) {
        this.mail = mail;
        this.password = password;
        this.name = name;
        this.surname = surname;
        this.publicvisibility = publicvisibility;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public boolean getPublicvisibility() {
        return publicvisibility;
    }

    public void setPublicvisibility(boolean publicvisibility) {
        this.publicvisibility = publicvisibility;
    }

    @XmlTransient
    public Collection<Event> getEventCollection() {
        return eventCollection;
    }

    public void setEventCollection(Collection<Event> eventCollection) {
        this.eventCollection = eventCollection;
    }

    @XmlTransient
    public Collection<Weathernotification> getWeathernotificationCollection() {
        return weathernotificationCollection;
    }

    public void setWeathernotificationCollection(Collection<Weathernotification> weathernotificationCollection) {
        this.weathernotificationCollection = weathernotificationCollection;
    }

    @XmlTransient
    public Collection<Ack> getAckCollection() {
        return ackCollection;
    }

    public void setAckCollection(Collection<Ack> ackCollection) {
        this.ackCollection = ackCollection;
    }

    @XmlTransient
    public Collection<Invite> getInviteCollection() {
        return inviteCollection;
    }

    public void setInviteCollection(Collection<Invite> inviteCollection) {
        this.inviteCollection = inviteCollection;
    }

    @XmlTransient
    public Collection<Invite> getInviteCollection1() {
        return inviteCollection1;
    }

    public void setInviteCollection1(Collection<Invite> inviteCollection1) {
        this.inviteCollection1 = inviteCollection1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (mail != null ? mail.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.mail == null && other.mail != null) || (this.mail != null && !this.mail.equals(other.mail))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jpa.entities.User[ mail=" + mail + " ]";
    }
    
}
